import React from 'react'
import { observable, action, toJS, computed } from 'mobx';
import { Tools, Popover } from 'weaver-mobile'
import { SearchAdvanced, ListAdvanced, RouteLayout, Browser, BrowserHrm, Upload, ListViewPage } from 'weaver-mobile-page';
import * as TaskMainApis from '../../api/task/taskMain'

const getLabel = Tools.getLabel;

export default class TaskDetailOperateLogStore {

    @observable
    datas = []

    @action
    changeDatas = (datas) => {
        this.datas = datas
    }

    @observable
    lastcount = 0

    @action
    changeLastcount = (lastcount) => {
        this.lastcount = lastcount
    }

    @observable
    lastid = ""

    @action
    changeLastid = (lastid) => {
        this.lastid = lastid
    }


    @observable
    taskid = ""

    @action
    changeTaskid = (taskid) => {
        this.taskid = taskid
    }

    @computed
    get logStore() {
        return new ListViewPage.Store({ route: '/taskHome/taskDetail/' + this.taskid })
    }

    //获取任务操作日志
    @action
    getTaskLog = (flag = false) => {
        TaskMainApis.getTaskLog({
            taskId: this.taskid,
            operation: "getLog",
            lastcount: this.lastcount,
            lastid: this.lastid,
            pagesize: 10
        }).then(res => {
            if (res.status === "1") {
                let tempArray = toJS(this.datas)
                tempArray.push(...res.datas)
                this.datas = tempArray

                const newState = {
                    isTable: false,
                    loading: false,
                    haveCheck: false,
                    template: { default: [] },
                    hasMore: res.lastcount > 0 ? true : false,
                    // data: res.datas && this.logStore.data.concat(res.datas),
                    data:flag ?  res.datas : res.datas && this.logStore.data.concat(res.datas)
                }
                this.logStore.setState(newState)
                this.logStore.updateDataSource()
                this.lastcount = res.lastcount
                this.lastid = res.lastid
            }
        })
    }
}